<?
if(!ANTIHACK) die("ANTIHACK...");
include_once(INCLUDES."buildlink.php");
include_once(INCLUDES."paging.php");
include_once(INCLUDES."split_unicode.php");
function getChild($id){
	$q=query("select * from menu where parent='$id'");
	$data[]=$id;
	while($r=fetch($q))
	{
		$arr=getChild($r["id"]);
		$data=array_merge($data, $arr);
	}
	return $data;
}
$table="post";
$code=$_GET['code'];
$q=query("select * from menu where code='$code'");
$r=fetch($q);
$id=$r["id"];
$listid=getChild($id);
$where=" parent in (".implode(',',$listid).")";
$total=0;$start=0;$limit=10;
$listpage= paging($table,$where,$_GET,$total,$start,$limit,5);
$start+=4;
//lay danh sach bai post
$data="";
$i=0;
$q=query("select * from $table where $where order by time desc limit 4");
while($r=fetch($q))
{
			$r['counter']=$i++;
			$r["time"]= date("H:i m/m/Y",$r["time"]);
			$r["link"]=buildlink("post",$r,"",1);
			$r["title"]=split_unicode($r["title"],60);
			$r["title"]=str_replace('"','“',$r["title"]);
			$r["title"]=str_replace('\'','“',$r["title"]);
			$r["described"]=split_unicode($r["described"],60);
			$r["described"]=str_replace('"','“',$r["described"]);
			$r["described"]=str_replace('\'','“',$r["described"]);
			$r["image"]=$r["image"]."|".$r["imgwidth"]."|".$r["imgheight"];
			$r["parentName"]=$parentName;
			$data[]=$r;
}
$q=query("select * from $table where $where order by time desc limit $start,$limit");
while($r=fetch($q))
{
			$r["time"]= date("H:i m/m/Y",$r["time"]);
			$r["link"]=buildlink("post",$r,"",1);
			$r["described"]=split_unicode($r["described"],200);
			$r["image"]=$r["image"]."|".$r["imgwidth"]."|".$r["imgheight"];
			$r["parentName"]=$parentName;
			$data1[]=$r;
}
##### Tiêu Điểm##########
$q=query("select * from $table where $where and is_showhome=1 order by time desc limit 10");
while($r=fetch($q))
{
			$r["time"]= date("H:i m/m/Y",$r["time"]);
			$r["link"]=buildlink("post",$r,"",1);
			$r["described"]=split_unicode($r["described"],300);
			$r["image"]=$r["image"]."|".$r["imgwidth"]."|".$r["imgheight"];
			$r["parentName"]=$parentName;
			$tieudiem[]=$r;
}
############ Trailer ################
$q=query("select * from $table where $where and is_showtrailer=1");
if($trailer=fetch($q))
{
	$code=explode("?v=",$trailer["trailer"]);
	$code=$code[1];
	$code=explode("&",$code);
	$code=$code[0];
	$trailer["code"]=$code;
	$trailer["link"]=buildlink("post",$trailer,"",1);
}
else
{
$trailer["trailer"]="";
}

$smarty->assign("listpage",$listpage);
$smarty->assign("curpage",$_GET["page"]);
$smarty->assign("data",$data);
$smarty->assign("data1",$data1);
$smarty->assign("tieudiem",$tieudiem);
$smarty->assign("trailer",$trailer);
$smarty->display("box1.htm");
?>>